package com.shop.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.domain.Product;
import com.shop.service.ProductService;

public class ShowProductServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3939434159706906069L;
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String id = req.getParameter("id");
		ProductService service = new ProductService();
		Product product = service.findProduct(id);
		System.out.println(product.getName());
		req.getSession().setAttribute("product", product);
		req.getRequestDispatcher("detail_product.jsp").forward(req, resp);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

}
